package demo2.demo1;

/**
 * Created with IntelliJ IDEA.
 * Description: 继承和多态学习
 * User: 阿宾
 * Date: 2024-05-13
 * Time: 16:55
 */
class Animal {
    public String name;
    public int age;
    public String color;

    //构造方法
    public Animal(String name) {
        this.name = name;
        System.out.println("父类构造方法");
    }
    public void eat(){
        System.out.println(this.name + "正在吃饭");
    }
}

//子类
class Dog extends Animal{
    //子类构造方法
    //快捷键：鼠标放到extends，然后Alt+回车
    public Dog(String name) {
        super(name);  //不能省略，因为构造方法带参，省略的情况只能是无参
        System.out.println("子类Dog构造方法");
    }

    public void wangWang() {
        System.out.println(name+" 正在旺旺旺！！");
    }
}
/*//子类
class Cat extends Animal{
    public Cat(String name) {
        super(name);
        System.out.println("子类cat的构造方法！");
    }
    public void miMi() {
        System.out.println(name+" 正在咪咪！！");
    }
}*/

public class Test01 {
    public static void main(String[] args) {

        Dog dog = new Dog("小狗");

        //发生向上转型
        Animal animal = new Dog("小狗");
    }
}
